package com.hhxy.rabbitmq.demo10;

import com.hhxy.rabbitmq.utils.RabbitMqUtil;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

/**
 * @author ghp
 * @date 2023/2/25
 * @title 消费者
 * @description
 */
public class Consumer02 {

    // 死信队列
    public static final String DEAD_QUEUE = "dead_queue";

    public static void main(String[] args) throws Exception{
        // 1、获取信道
        Channel channel = RabbitMqUtil.getChannel();

        // 5、接收消息
        System.out.println("Consumer02等待接收死信消息...");
        DeliverCallback deliverCallback = (consumerTag, message) -> {
            System.out.println("死信消息消费成功: "+new String(message.getBody()));
        };
        CancelCallback cancelCallback = (consumerTag) -> {
            System.out.println("死信消息消费失败!");
        };
        channel.basicConsume(DEAD_QUEUE, true, deliverCallback, cancelCallback);
    }

}
